package com.bite.book.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
//标识这是一个切面类
@Aspect
@Component
/**
 * 记录每个方法的耗时
 */
public class TimeAspect {
    //环绕通知 标识方法执行前后的内容都会被执行
    @Around("execution(* com.bite.book.controller.*.*(..))")
    public Object recordTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Long begin = System.currentTimeMillis();
        //执行原始方法
        Object result = proceedingJoinPoint.proceed();
        Long end = System.currentTimeMillis();
        log.info(proceedingJoinPoint.getSignature() + "执行耗时: {}ms",end - begin);
        return result;

    }
}
